Page({
	data: {
		path: "", //图片路径
		btnText: "", // 按钮文字
		jumpPath: "", // 跳转路径
		jumpType: "", // 跳转类型
		appId: "", //第三方的小程序id
	},
	onLoad: function (options) {
		this.setData({
			path: decodeURIComponent(options.path),
			btnText: options.btnText,
			jumpPath: options.jumpPath ? decodeURIComponent(options.jumpPath) : "",
			jumpType: options.jumpType,
			appId: options.appId,
		})
		//动态设置页面标题
		if (options.title) {
			wx.setNavigationBarTitle({
				title: decodeURIComponent(options.title),
			})
		}
	},
	imageClick() {
		//如果配置了按钮跳转则点击图片不跳转
		if (this.data.btnText) {
			return
		}
		this.jump()
	},
	btnClick() {
		this.jump()
	},
	jump() {
		switch (this.data.jumpType) {
			//跳转到当前小程序的页面
			case "jumpPage":
				wx.redirectTo({
					url: this.data.jumpPath,
				})
				break
			//跳转到h5页面
			case "jumpH5":
				wx.navigateTo({
					url:
						"/pages/web/web?path=" +
						encodeURIComponent(this.data.jumpPath),
				})
				break
			//跳转到第三方小程序
			case "jumpMiniProgram":
				wx.navigateToMiniProgram({
					appId: this.data.appId,
					path: this.data.jumpPath,
					success: function (res) {
						console.log("success", res)
					},
					fail: function (err) {
						console.log("fail", err)
					},
				})
				break
		}
	},
})
